package controller;

import entity.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import serviceimpl.AdminServiceImpl;
import util.MD5Util;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/admin")
public class AdminLoginAndRegisterController {
    @Autowired
    AdminServiceImpl adminService;


    @RequestMapping("/login")
    public String login(@RequestParam String username, @RequestParam String password){
        return adminService.login(username,password) ;
    }

    @RequestMapping("/register")
    public String register(@RequestParam String username, @RequestParam String password, @RequestParam String email, HttpServletResponse res){
//        res.setHeader("Access-Control-Allow-Origin","*");
        return  adminService.register(new Admin(username, MD5Util.MD5PassWord(password),email,new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));
    }


}
